package com.zeng.filter;

import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

/**
 * @author Zqm
 * @Title: MyTypeFilter
 * @ProjectName SpringAnnotationDriven
 * @date 2019/1/10
 * 自定义 包扫描过滤器
 */
public class MyTypeFilter implements TypeFilter {

    /**
     *
     * @param metadataReader  当前正在扫描类的信息
     * @param metadataReaderFactory  获取其他任何类信息的工厂
     * @return
     * @throws IOException
     */
    @Override
    public boolean match(MetadataReader metadataReader,
                         MetadataReaderFactory metadataReaderFactory) throws IOException {
        //获取当前注解的信息
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
        //获取当前正在扫描的类信息
        ClassMetadata classMetadata = metadataReader.getClassMetadata();
        //获取当前正在扫描的类资源信息
        Resource resource = metadataReader.getResource();

        String className = classMetadata.getClassName();
        System.out.println("自定义过滤器....."+className);
        if(className.contains("er")){
            return true;
        }
        return false;
    }
}
